/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.ce.commands.bankacc;

import com.bionic.ce.beans.Bankacc;
import com.bionic.ce.businesslogic.BankAccService;
import com.bionic.ce.commands.ICommand;
import com.bionic.ce.manager.Config;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author MAXIM
 */
public class CommandSelectBankAccount implements ICommand {

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null;
        try {
            Integer bankAccid = Integer.parseInt(request.getParameter("bankaccid"));
            Bankacc bankAcc = BankAccService.returnCurrentBankAccInfo(bankAccid);
            request.getSession().setAttribute("bankacc", bankAcc);
            page = Config.getInstance().getProperty(Config.GOTOBANKACCINFO);
        } catch (NumberFormatException e) {
            request.setAttribute("error", "Please choose bank account");
            //request.getSession().setAttribute("error", "Please choose bank account");
            page = Config.getInstance().getProperty(Config.GOTOBANKACCAOUNTSINFO);
        }

        return page;
    }
}